import { upDownUpload } from '@/api/file/upDown';
export function useUpload() {
  const state = reactive({
    data: null,
    error: null
  });
  const upload = async (file) => {
    try {
      if (!file) {
        throw new Error('不存在file');
      }
      const formData = new FormData();
      formData.append('file', file);
      const data = await upDownUpload(formData);
      state.data = data;
      return data;
    } catch (error) {
      state.error = error;
    }
  };
  return {
    upload,
    ...toRefs(state)
  };
}
/** 使用示例
 * const {upload,data} = useUpload()
 * await upload(file)
 * if(data.code===200&&data.data){
 *  console.log(data.data,)
 * }
 *
 */
